package com.zhanbo.zhanbowymusic.dialog;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.mwx.baselib.base.BaseBindingAdapter;
import com.mwx.baselib.bean.SceneListBean;
import com.zhanbo.zhanbowymusic.R;
import com.zhanbo.zhanbowymusic.main.featured.adapter.FeaturedHomeNewMusicListAdapter;
import com.zhanbo.zhanbowymusic.main.featured.adapter.FeaturedSceneListAdapter;

import java.util.List;

public class ScenePop extends PopupWindow {
    private final FeaturedSceneListAdapter featuredSceneListAdapter;
    private RecyclerView recyclerView;
    private Context context;
    @SuppressLint("MissingInflatedId")
    public ScenePop(Context context) {
        super(context);
        this.context =context;
        View view = LayoutInflater.from(context).inflate(R.layout.pop_scene,null);
        setContentView(view);
        setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        setBackgroundDrawable(null);
        setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED);
        setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        setOutsideTouchable(false);
        setFocusable(true);
        recyclerView = view.findViewById(R.id.rv_scene);
        recyclerView.setLayoutManager(new GridLayoutManager(context, 3));
         featuredSceneListAdapter = new FeaturedSceneListAdapter(context);
        recyclerView.setAdapter(featuredSceneListAdapter);
        featuredSceneListAdapter.setOnItemClickListener(new BaseBindingAdapter.OnItemClickListener<SceneListBean.ItemsDTO>() {
            @Override
            public void onItemClick(int position) {
                for (SceneListBean.ItemsDTO item : featuredSceneListAdapter.getItems()) {
                    item.setCheck(false);
                }
                featuredSceneListAdapter.getItems().get(position).setCheck(true);
                featuredSceneListAdapter.notifyDataSetChanged();
                mScenePopOnItemClickListener.onItemClick(featuredSceneListAdapter.getItems().get(position));
            }
        });

    }
    protected ScenePopOnItemClickListener mScenePopOnItemClickListener;

    public void setOnItemClickListener(ScenePopOnItemClickListener mScenePopOnItemClickListener) {
        this.mScenePopOnItemClickListener = mScenePopOnItemClickListener;

    }
    public interface ScenePopOnItemClickListener {

        void onItemClick(SceneListBean.ItemsDTO itemsDTO);
    }
    public void setSceneList(List<SceneListBean.ItemsDTO> sceneList) {

        featuredSceneListAdapter.getItems().addAll(sceneList);
        featuredSceneListAdapter.notifyDataSetChanged();

    }


}
